<?php
/*
 * description：
 * author：wh
 * email：
 * createTime：{2020/5/29} {18:09} 
 */

namespace extend\model;


use think\Db;

class AutoCodeModel extends BaseModel
{
    static $self_table = 'web_auto_code';

    static function getAutoCodeList(){
        $auto_obj = Db::name(self::$self_table);
        $auto_obj->where(['is_deleted'=>0]);
        return $auto_obj->select();
    }
    static function getAutoCodeListOrderById(){
        $auto_obj = Db::name(self::$self_table);
        $auto_obj->where(['is_deleted'=>0]);
        $auto_obj->order('id DESC');
        return $auto_obj->select();
    }


    static function getAutoCodeById(int $id){
        $auto_obj = Db::name(self::$self_table);
        $auto_obj->where(['is_deleted'=>0, 'id'=>$id]);
        return $auto_obj->find();
    }

    static function getAutoCodeByDbName(string $dbname){
        $auto_obj = Db::name(self::$self_table);
        $auto_obj->where(['is_deleted'=>0, 'dbname'=>$dbname]);
        return $auto_obj->find();
    }

    static function getAutoCodeByController(string $controller){
        $auto_obj = Db::name(self::$self_table);
        $auto_obj->where(['is_deleted'=>0, 'controller'=>$controller]);
        return $auto_obj->find();
    }

    static function getAutoCodeInTablesIsSyncRedis(array $tables){
        $auto_obj = Db::name(self::$self_table);
        $auto_obj->where(['is_deleted'=>0, 'is_sync_redis'=>1]);
        $auto_obj->where('dbname', 'in', $tables);
        return $auto_obj->select();
    }
}